#include <QApplication>
#include <QDebug>

#include "HtmlWidget.h"

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    // 创建HtmlWidget实例
    HtmlWidget widget;
    widget.resize(800, 600);
    widget.setWindowTitle("HTML Renderer Demo");

    // 创建一个简单的HTML文档
    std::string html = R"(
        <!DOCTYPE html>
        <html>
        <head>
            <style>
                body { font-family: Arial, sans-serif; margin: 20px; background-color:white;}
                h1 { color: #333; }
                p { line-height: 1.6; }
                .highlight { background-color: #ffffcc; padding: 10px; }
                ul { color: #666; }
            </style>
        </head>
        <body>
            <h1>Hello, LiteHTML with Qt!</h1>
            <p>This is a simple demonstration of rendering HTML content using LiteHTML and Qt.</p>
            <div class="highlight">
                <p>This text is highlighted.</p>
            </div>
            <h2>Features:</h2>
            <ul>
                <li>Basic HTML rendering</li>
                <li>CSS styling support</li>
                <li>Text formatting</li>
                <li>Lists and tables</li>
            </ul>
        </body>
        </html>
    )";

    try {
        // 创建litehtml文档
        litehtml::document::ptr doc =
            litehtml::document::createFromString(html.c_str(), &widget);
        if (doc) {
            // 设置文档到widget
            widget.setHtmlDocument(doc);

            // 显示窗口
            widget.show();

            // 运行应用程序
            return app.exec();
        } else {
            qDebug() << "Failed to create HTML document";
        }
    } catch (const std::exception &e) {
        qDebug() << "Exception:" << e.what();
    }

    return -1;
}
